package internal

import (
	"bytes"
	"github.com/BurntSushi/toml"
	"log"
	"yh-oss-convert/config"
)

func Init(configPath string) {
	_, err := toml.DecodeFile(configPath, &config.MyConfig)
	if err != nil {
		log.Fatal(err)
	}
	if config.MyConfig.Path == "" {
		log.Fatal("没有配置文件保存路径")
	}
	if config.MyConfig.MaxGoroutine > 1000 {
		config.MyConfig.MaxGoroutine = 1000
	}
	if config.MyConfig.MaxGoroutine == 0 {
		config.MyConfig.MaxGoroutine = 20
	}
	initLogConfig()
	var firstBuffer bytes.Buffer
	e := toml.NewEncoder(&firstBuffer)
	_ = e.Encode(config.MyConfig)
}
